<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="描述">
              <a-input placeholder="请输入描述" v-model="queryParam.description"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="处理人员">
              <a-input placeholder="请输入处理人员" v-model="queryParam.handleMan"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="处理备注">
                <a-input placeholder="请输入处理备注" v-model="queryParam.handleNote"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="处理时间">
                <a-input placeholder="请输入处理时间" v-model="queryParam.handleTime"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="会员用户名">
                <a-input placeholder="请输入会员用户名" v-model="queryParam.memberId"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
          </a-dropdown>
        </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span v-if="record.status==0" slot="action" slot-scope="text, record">
          <a-popconfirm title="确定通过吗?" @confirm="() => audit(record.id,1,record.returnPrice,'')">
            <a>通过</a>
          </a-popconfirm>
          <a-divider type="vertical"/>
          <a @click="reject(record)">不通过</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <a-modal
      title="确认审核不通过"
      :width="800"
      :visible="auditVisible"
      @ok="auditReject"
      @cancel="auditModalCancel"
      cancelText="关闭">
      <a-textarea
        v-model="rejectReason"
        placeholder="不通过原因"
        :autosize="{ minRows: 2, maxRows: 6 }"
      />
    </a-modal>
    <!-- 表单区域 -->
    <omsOrderReturn-modal ref="modalForm" @ok="modalFormOk"></omsOrderReturn-modal>
  </a-card>
</template>

<script>
  import OmsOrderReturnModal from './modules/OmsOrderReturnModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {doMian} from '@/api/api'
  import {getAction, deleteAction, putAction, postAction, putActionObj} from '@/api/manage'

  export default {
    name: "OmsOrderReturnList",
    mixins: [JeecgListMixin],
    components: {
      OmsOrderReturnModal
    },
    data() {
      return {
        auditVisible: false,
        handelRecord: {},
        rejectReason: '',
        description: '订单退货管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            hidden:true,
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '处理人员',
            align: "center",
            dataIndex: 'handleMan'
          },
          {
            title: '处理时间',
            align: "center",
            dataIndex: 'handleTime'
          },
          {
            title: '会员用户名',
            align: "center",
            dataIndex: 'memberId'
          },
          {
            title: '订单id',
            align: "center",
            dataIndex: 'orderId'
          },
          {
            title: '品种数量',
            align: "center",
            dataIndex: 'productTypeCount'
          },
          {
            title: '原因',
            align: "center",
            dataIndex: 'handleNote'
          },
          {
            title: '收货备注',
            align: "center",
            dataIndex: 'receiveNote'
          },
          {
            title: '收货时间',
            align: "center",
            dataIndex: 'receiveTime'
          },
          {
            title: '收货人',
            align: "center",
            dataIndex: 'receiver'
          },
          {
            title: '收货地址',
            align: "center",
            dataIndex: 'receiverAddress'
          },
          {
            title: '收货人手机号码',
            align: "center",
            dataIndex: 'receiverPhone'
          },
          {
            title: '退款总金额',
            align: "center",
            dataIndex: 'returnPrice'
          },
          {
            title: '申请状态：0->待处理；1->退货中；2->已完成；3->已拒绝',
            align: "center",
            dataIndex: 'status'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: 120,
            align: "center",
            scopedSlots: {customRender: 'action'},
          }
        ],
        url: {
          list: "/oms/omsOrderReturn/list",
          delete: "/oms/omsOrderReturn/delete",
          deleteBatch: "/oms/omsOrderReturn/deleteBatch",
        },
      }
    },
    computed: {},
    methods: {
      audit(id, status, returnPrice, reason) {
        var that = this;
        postAction("/oms/omsOrderReturn/handle", {
          orderReturnId: id,
          status: status,
          returnPrice: returnPrice,
          handleNote: reason
        }).then((res) => {
          that.auditVisible = false;
          if (res.success) {
            that.loadData();
          }
        });
      },
      reject(record) {
        this.auditVisible = true;
        this.handelRecord = record;
      },
      auditReject() {
        this.audit(this.handelRecord.id, 3, this.handelRecord.returnPrice, this.rejectReason);
      },

      auditModalCancel() {
        this.auditVisible = false;
      }

    }
  }
</script>
<style lang="less" scoped>
  /** Button按钮间距 */
  .ant-btn {
    margin-left: 3px
  }

  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
</style>